;
define(function (required, exports, modules) {
    var modal = require('mods/modal')
    exports.add_permission = function () {
        $('.add').click(function () {
            if ($(this).hasClass('disabled')) {
                modal.alert('系统正在处理中,请不要重复请求')
                return false
            }

            var permission_name = $('input[name=permission]').val()
            var old_name = $('input[name=old_name]').val()
            var _csrf = $('#csrf').val()

            if (permission_name.length < 1) {
                modal.msg('权限名称不能为空')
                return false
            }
            $(this).addClass('disabled')
            $.ajax({
                url: '/admin/permissions/add-permissions',
                type: 'POST',
                dataType: 'json',
                data: {
                    name: permission_name,
                    old_name: old_name,
                    _csrf: _csrf
                },
                success: function (res) {
                    $(this).removeClass('disabled')
                    if (res.code == 200) {
                        modal.msg(res.msg, {}, function () {
                            window.location.href = '/admin/permissions/index'
                        })
                    } else {
                        modal.alert(res.msg)
                        return false
                    }
                }
            })
        })
    }
})